import { Message } from 'element-ui'

/**
 * @type {import('@/types/global').useCopy}
 */
const useCopy = (text) => {
  text = text ? text : ' '
  try {
    navigator.clipboard.writeText(text).then(() => Message.success('复制成功'))
  } catch (error) {
    const input = document.createElement('input')
    input.value = text
    document.body.appendChild(input)
    input.select()
    document.execCommand('Copy')
    document.body.removeChild(input)
    Message.success('复制成功')
  }
}

export default useCopy
